package zcjq.d914;

import java.util.Scanner;

public class P1 {

    public static int solve(String s) {
        int n = (s.length() + 2) / 3;
        if (n < 2) {
            return 0;
        }
        int total = 0;
        for (int i = 2; i <= n; i++) {
            int len = 3 * i - 2;
            for (int begin = 0; begin <= s.length() - len; begin++) {
                String sub = s.substring(begin, begin + len);
                if (checkValid(sub, i)) {
                    total++;
                }
            }
        }
        return total;
    }

    private static boolean checkValid(String sub, int n) {
        for (int i = 1; i <= n; i++) {
            char a = sub.charAt(i - 1);
            char b = sub.charAt(2 * n - i - 1);
            char c = sub.charAt(2 * n + i - 2 - 1);
            if (a != b || a != c || b != c) {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = Integer.parseInt(scanner.nextLine().trim());
        while (N-- > 0) {
            System.out.println(solve(scanner.nextLine().trim()));
        }
    }
}
